package com.qf.efserver.discover.controller;

import com.qf.common.core.annotation.NoLoginCheck;
import com.qf.common.core.common.R;
import com.qf.efserver.discover.service.DiscoverService;
import com.qf.efserver.food.VO.RecommendFoodVO;
import com.qf.efserver.food.param.AddCustomizeNutritionParam;
import com.qf.efserver.food.param.UpdateCustomizeNutritionParam;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * Author hehecheng
 * Date 2024/11/9
 * 祝我们都能遇见真诚的人
 * 见字如面
 */
@RestController
@RequestMapping("/discover")
@Api(tags = "发现模块api")
public class DiscoverController {

    @Autowired
    private DiscoverService discoverService;

    /**
     * 发现推荐接口
     *
     * @return
     */
    @ApiOperation(value = "发现推荐接口", notes = "推荐食物")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = RecommendFoodVO.class, responseContainer = "List"),
    })
    @GetMapping("/recommendFood")
    public R<List<RecommendFoodVO>> recommendFood() {
        List<RecommendFoodVO> recommendFoodVOS = discoverService.recommendFood();
        return R.ok(recommendFoodVOS);
    }

    /**
     * 发现最近接口
     *
     * @return
     */
    @ApiOperation(value = "发现最近接口", notes = "最近推荐的食物")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = RecommendFoodVO.class, responseContainer = "List"),
    })
    @GetMapping("/recentFood")
    public R<List<RecommendFoodVO>> recentFood() {
        List<RecommendFoodVO> recommendFoodVOS = discoverService.recentFood();
        return R.ok(recommendFoodVOS);
    }

    /**
     * 添加自定义食物
     *
     * @param addCustomizeNutritionParam
     * @return
     */
    @ApiOperation(value = "用户定制食物", notes = "用户自定义的食物")
    @PostMapping("/addCustomize")
    public R addCustomizeNutrition(@RequestBody AddCustomizeNutritionParam addCustomizeNutritionParam) {
        discoverService.addCustomizeNutrition(addCustomizeNutritionParam);
        return R.ok();
    }

    /**
     * 展示用户定制的食物
     *
     * @return
     */
    @ApiOperation(value = "展示用户定制的食物", notes = "展示用户自定义的食物")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = RecommendFoodVO.class, responseContainer = "List"),
    })
    @GetMapping("/userCustomize")
    private R<List<RecommendFoodVO>> customizeNutritionList() {
        List<RecommendFoodVO> customize = discoverService.customizeNutritionList();
        return R.ok(customize);
    }

    /**
     * 用户修改自定义食物
     *
     * @return
     */
    @ApiOperation(value = "修改用户自定义的食物", notes = "对用户自己添加的定制食物进行修改")
    @PostMapping("/updateCustomize")
    public R updateCustomizeNutrition(@RequestBody UpdateCustomizeNutritionParam updateCustomizeNutritionParam) {
        discoverService.updateCustomizeNutrition(updateCustomizeNutritionParam);
        return R.ok();
    }

    /**
     * 删除用户自定义食物
     *
     * @param foodId
     * @return
     */
    @ApiOperation(value = "删除自己自定义的食物", notes = "用户删除自己自定义的食物")
    @ApiParam(name = "foodId", value = "食物id")
    @PostMapping("/delCustomize")
    public R delCustomizeNutrition(Integer foodId) {
        discoverService.delCustomizeNutrition(foodId);
        return R.ok();
    }

    /**
     * 自定义食物图片上传
     *
     * @param file
     * @return
     */
    @NoLoginCheck
    @ApiOperation(value = "用户定制食物图片上传")
    @PostMapping("/upload")
    public R<String> upload(@RequestPart("file") MultipartFile file) {
        String path = discoverService.upload(file);
        return R.ok(path);
    }


}
